package GUI;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.Color;

import javax.swing.border.LineBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import classes.Funcionario;
import fachada.Fachada;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class Excluir_Funcionario {

	private JFrame frame;
	private JTextField txbid;
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Excluir_Funcionario window = new Excluir_Funcionario();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Excluir_Funcionario() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 640, 484);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new LineBorder(new Color(0, 0, 0), 2));
		panel.setBackground(Color.BLUE);
		panel.setBounds(0, 0, 624, 81);
		frame.getContentPane().add(panel);
		
		JLabel label = new JLabel("Alera\u00E7\u00E3o de Funcion\u00E1rio");
		label.setForeground(Color.WHITE);
		label.setFont(new Font("Tahoma", Font.BOLD, 16));
		label.setBounds(291, 27, 197, 20);
		panel.add(label);
		
		JPanel panel_1 = new JPanel();
		panel_1.setLayout(null);
		panel_1.setBorder(new LineBorder(new Color(0, 0, 0), 2));
		panel_1.setBackground(Color.BLUE);
		panel_1.setBounds(0, 367, 624, 81);
		frame.getContentPane().add(panel_1);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(97, 133, 334, 202);
		frame.getContentPane().add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"ID", "Nome"
			}
		));
		scrollPane.setViewportView(table);
		
		JLabel lblSelecioneOFuncionrio = new JLabel("Selecione o funcion\u00E1rio a ser exclu\u00EDdo:");
		lblSelecioneOFuncionrio.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblSelecioneOFuncionrio.setBounds(140, 109, 306, 14);
		frame.getContentPane().add(lblSelecioneOFuncionrio);
		
		JButton button = new JButton("Pesquisar");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Fachada f = new Fachada();
				;
				ArrayList<Funcionario> listfun = new ArrayList();
				if(txbid.getText().trim().equals("")){
				try {
					listfun=(ArrayList) f.consultarTodosFuncionario();
						
					
				} catch (Exception e) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(null,e.getMessage());
				}						
				}else{try {
					
					long id = Long.parseLong(txbid.getText());
					
						Funcionario fun = new Funcionario();
						fun=f.consultarFuncionarioPorId(id);
							
						
					} catch (Exception e) {
						// TODO Auto-generated catch block
						JOptionPane.showMessageDialog(null,e.getMessage());
					}	
						
					}}
				
			
		});
		button.setBounds(466, 200, 89, 23);
		frame.getContentPane().add(button);
		
		txbid = new JTextField();
		txbid.setColumns(10);
		txbid.setBounds(456, 168, 102, 20);
		frame.getContentPane().add(txbid);
		
		JLabel label_2 = new JLabel("Pesquisar Id:");
		label_2.setFont(new Font("Tahoma", Font.BOLD, 14));
		label_2.setBounds(456, 144, 96, 14);
		frame.getContentPane().add(label_2);
	}

}
